#!/usr/bin/env python
import os
print os.getcwd()
from PyQt4 import QtGui
import notes
text_to_note_dict = {}

octave1_text = 'q2w3er5t6y7ui9o0p[=]'
octave1_notes = notes.noterange('C3', 'G4')

octave2_text = 'zsxdcvgbhnjm,l.;/'
octave2_notes = notes.noterange('C4', 'E5')


for text, note in zip(octave1_text, octave1_notes):
    text_to_note_dict[text] = note
    
for text, note in zip(octave2_text, octave2_notes):
    text_to_note_dict[text] = note

def getnotebytext(text):
    return text_to_note_dict[unicode(text)]

class PianoWidget(QtGui.QLabel):
    def __init__(self):
        QtGui.QLabel.__init__(self)
        self.setText('Hello!')

    def keyPressEvent(self, e):
        if e.isAutoRepeat():
            return
        try:
            note = getnotebytext(e.text())
        except KeyError: 
            return

        note.play()
    
    def keyReleaseEvent(self, e):
        try:
            note = getnotebytext(e.text())
        except KeyError:
            return
        note.stop()
        
app = QtGui.QApplication([])
w = PianoWidget()
w.show()
app.exec_()
